[contents] [prev] [next] [top] [bottom] (5 out of 12)

Assignment and Variable Access

The ScriptX assignment expression assigns the value of a simple expression to a location. A location is either the name of a global or local variable, a specifier for some object's instance variable, or a specifier for an element in a collection.

assignmentExpr	::=	location := simpleExpr 
	|	location := assignmentExpr 
	|	location := guardExpr 
location	::=	symbol 
	|	ivAccess 
	|	elementAccess 

An assignment expression yields the value that is assigned. This allows assignment expressions to be cascaded or embedded within other expressions.

ScriptX provides a choice in syntax for instance variable access. In the possessive form, a separator is required before the symbol. Instance variable access associates left-to-right, so expressions can be nested to allow for access to instance variables defined by embedded objects.

ivAccess	::=	factor.symbol 

ScriptX uses brackets to identify elements of a collection in an element access expression. Note that the brackets in the element access expression are not meta-characters of the EBNF grammar.

elementAccess	::=	factor [ simpleExpr ] 

A binding is an association between a symbol, or lexical name, and a global or local variable. A binding can be declared local or global. An assignment statement or a class or object definition expression stores a pointer to some object at that location. Objects do not necessarily have to have a binding-they can be embedded within other objects. Objects can also have more than one binding.

binding	::=	variable 
funBindings	::=	functionDefExpr [ , functionDefExpr ]* 
	|	freeMethDefExpr [ , freeMethDefExpr ]* 

A local declaration is allowed only at the inner level, inside the scope for which the binding is local. An explicit global declaration is allowed only at the top level. If the scope of a declaration is not given explicitly, it is global by default. Of course, a global declaration is global only within modules that use its definition. The unglobal version of the global expression removes a global binding.

localExpr	::=	local binding [ , binding ]* 
	|	local funBindings 
globalExpr	::=	global binding [ , binding ]* 
	|	global funBindings 

A variable is a symbol that is associated with some location through a binding. When a variable is declared, it is initialized automatically. The compiler offers several options at initialization. A variable can be declared constant, meaning that its value cannot later be changed by assignment. A variable can be associated with a restriction. (Although the restriction syntax is legal in any variable declaration, restrictions are currently implemented only in free method definitions. Otherwise, restrictions are ignored.) A variable can be assigned an initial value. If no value is assigned to a variable when it is declared, its value is set to undefined, a special object.

variable	::=	[ constant ] symbol [ restriction ] [ initialVal ] 
restriction 	::=	{ class factor } 
	|	{ kind factor } 
	|	{ object factor } 
initialVal	::=	: simpleExpr 
	| 	:= simpleExpr 


This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.

Copyright 1996 Apple Computer, Inc. All Rights Reserved.